package com.tuoren.forward.config;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;

import com.zaxxer.hikari.HikariDataSource;

//@Configuration
public class OtherDataSourceConfiguration {

	

    @Bean("nbDataSourceProperties")
    @ConfigurationProperties("spring.datasource.nb")
    public DataSourceProperties nbDataSourceProperties() {
        return new DataSourceProperties();
    }

    @Bean("nbDataSource")
    @Qualifier(value = "nbDataSource")
    // 留意下面这行
    @ConfigurationProperties(prefix = "spring.datasource.nb.hikari")
    public HikariDataSource nbDataSource(@Qualifier("nbDataSourceProperties") DataSourceProperties nbDataSourceProperties) {
        return nbDataSourceProperties.initializeDataSourceBuilder().type(HikariDataSource.class).build();
    }


    @Bean( "nbJdbcTemplate")
    @Qualifier(value = "nbJdbcTemplate")
    public JdbcTemplate secondaryJdbcTemplate(@Qualifier("nbDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}
